package org.zcl.filter;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * api过滤器
 *
 * @author zhuchenglin
 * @date 2022/09/06 16:22
 * @since 2022/9/6 15:44
 */
@Slf4j
public class ApiFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;
        Map<String, String[]> map = req.getParameterMap();
        log.info("请求：{}，入参:{}", req.getRequestURL(), JSON.toJSONString(map));
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        chain.doFilter(request, response);
    }
}
